<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>工单及非工单领出编辑</title>
<!-- import css and js -->
<%@ include file="/common/metaInput.jsp"%>
<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
<script type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${ctx}/js/jsp/yd/logic/ItemStateData.js"></script>
<script type="text/javascript">
	var basic_Url = "${ctx}/yd/logic/proget";
	$(function() {
		$("#inputForm").validate({
			onsubmit : true,
			/*执行ajaxsubmit  */
			submitHandler : function(editform) {

				//alert(jsonInfo); 
				try {
					url = basic_Url + "/save.do";
					var api = frameElement.api;
					var W = api.opener;

					getReturnMessage(url, "inputForm", W.searchAP);
				} catch (e) {
					alert(e)
				}
			}
		});
		
		if ('${viewflag}' == "add"){
			$("#save1").hide();
			$("#save2").hide();
			$("#save3").hide();
			$("#tr1").hide();
		}else if ('${viewflag}' == "tijiao"){
			$("#save").hide();
			$("#save2").hide();
			$("#save3").hide();
			if($("#createRName").val()!="${user.name}"){
				$("#save1").hide();
				$("input[type!='hidden']").attr("readonly","readonly");
				$("select").attr("disabled","disabled");//禁用SELECT标签
				$("textarea").attr("readonly","readonly");//禁用TEXTAREA标签
			}
		}else if ('${viewflag}' == "shenpi"){
			$("#save").hide();
			$("#save1").hide();
			$("input[type!='hidden']").attr("readonly","readonly");//禁用SELECT标签
			$("select").attr("disabled","disabled");//禁用SELECT标签
			$("textarea").attr("readonly","readonly");//禁用TEXTAREA标签
		}else if ('${viewflag}' == "tongguo"){
			$("#save1").hide();
			$("#save2").hide();
			$("#save3").hide();
			$("#save").hide();
			$("input[type!='hidden']").attr("readonly","readonly");//禁用SELECT标签
			$("select").attr("disabled","disabled");//禁用SELECT标签
			$("textarea").attr("readonly","readonly");//禁用TEXTAREA标签
		}else if ('${viewflag}' == "bhtijiao"){
			$("#save").hide();
			$("#save2").hide();
			$("#save3").hide();
			if($("#createRName").val()!="${user.name}"){
				$("#save1").hide();
				$("input[type!='hidden']").attr("readonly","readonly");
				$("select").attr("disabled","disabled");//禁用SELECT标签
				$("textarea").attr("readonly","readonly");//禁用TEXTAREA标签
			}
		}
	})
	function submitForm(param) {
	 	$("#billStatus").val(param);
	 	$("#whName").val($("#whCode").find("option:selected").text());
	 	$("#addressInfos").val(JSON.stringify($("#dataGrid1").ligerGetGridManager().getData()));
		var data = $("#dataGrid1").ligerGetGridManager().getData();
		if(data.length==0){
			$.dialog.alert("请先选择领料申请单");
	   	 	return false;
		}
		var ba = true;
		if(data !=null){
			for (var i = 0;i < data.length;i++){
				var row = data[i]; 
// 				if(undefined == row.batch||row.batch==null||row.batch==""){
// 		           	 $.dialog.alert("您第"+(i+1)+"行的“批次”不合法");
// 		           	 ba=false;
// 		           	 return false;
// 		        }
				if(row.openBatch != "Y"){
								if (undefined == row.status||row.status==""
									|| null == row.status) {
									$.dialog.alert("第" + (i+1) + "行的状态没有选择");
									ba = false;
									return false;
								}
								
				}
				if (undefined == row.unit|| null == row.unit||row.unit=="") {
					$.dialog.alert("第" + (i+1) + "行的单位没有选择");
					ba = false;
					return false;
				}
				if(undefined == row.quantuty
						|| isNaN(row.quantuty)
						|| row.quantuty<= 0){
	           	 $.dialog.alert("您第"+(i+1)+"行的出库数量不合法");
	           	 ba = false;
	           	 return false;
	            }
	            if (parseFloat(row.actureQuantity) > parseFloat(row.kcsl)){
	        	   $.dialog.alert("您第"+(i+1)+"行的出库数量大于库存数量");
	        	   ba = false;
		           return false;
	           }
 			}
// 			for ( var i = 0; i < data.length; i++) {
// 				var num =parseFloat(data[i].actureQuantity);
// 				for ( var j = 0; j < data.length; j++) {
// 					if(i != j){
// 						if(data[i].code==data[j].code && data[i].batch==data[j].batch && data[i].status==data[j].status){
// 							ba = false;
// 							$.dialog.alert("物料编码为:" + data[j].code + "的第"+(i+1)+"行与第"+(j+1)+"行存在相同的批次与等级!");
// 							return false;
// 						}else if(data[i].code==data[j].code){
// 							num +=parseFloat(data[j].actureQuantity);
// 							if(num>(parseFloat(data[i].jquantuty)-parseFloat(data[i].ycksl==null ? 0.0 :data[i].ycksl))){
// 								ba = false;
// 								$.dialog.alert("物料编码为:" + data[j].code + "的“出库数量”大于“订单数量”");
// 								return false;
// 							}
// 						}
// 					}
// 				}
// 			}
		}
		//设置ajax全局同步
		jQuery.ajaxSettings.async = false;
		if(ba){
			$("#submitFlag").val(param);
			$("#inputForm").submit();
		}
	}

	function tableSubmit(msg,param){
		$.ligerDialog.confirm(msg, 
				function (flag) { 
				if(flag){
					submitForm(param);
					}
			}); 
	}

	function submitpass(param){
		tableSubmit('是否确认审核通过？',param);
	}
	function getA(){
		$("#whName").val($("#whCode").find("option:selected").text());
	}
	
	function getB(){
		if($("#whCode").val()==""){
			$.dialog.alert("请先选择出库仓库！");
			return false;
		}
		if($("#oriCode").val()==""){
			$.dialog.alert("您选择的申请单号不能为空！");
			return false;
		}
		<c:forEach items='${apply}' var='state'>
			if('${state.getProCode}'==$("#oriCode").val()){
				$("#deptcode").val('${state.oriCode}');
			}
        </c:forEach>
		
        multipleSearch("#dataGrid1",true,"",basic_Url+"/applyItemList.do?code="+$("#oriCode").val());
	}
	
	function check(){
		$.ajax({
		      url: "${ctx}/yd/logic/proget/updateState.do",
		      global: false,
		      type: "POST",
		      dataType: "json",
		      data: ({
		    	   rows:$("#id").val()
		      }),		     
		      success: function(msg){
		    	  if(msg.msg=="SUCCESS"){
		    		  $.dialog.alert("驳回成功",function(){close();});
		    	  }
		    	  if(msg.msg=="ERROR"){
		    		  $.dialog.alert("操作失败",function(){close();});
		    	  }
		   }
		});
	}
	
	function close(){
		var api = frameElement.api;
		var W = api.opener;
		CloseDialog();
		W.searchAP();
	}
</script>

</head>

<body>

	<form id="inputForm" action="" method="post">
		<input type="hidden" id="id" name="id" value="${oi.id}" />
		<input type="hidden" id="addressInfos" name="addressInfos"/>
		<input type="hidden" id="dataItem" name="dataItem"/>
		<input type="hidden" id="batchItem" name="batchItem"/>
		<input type="hidden" id="varsion" name="varsion" value="${oi.varsion}"/>
		<input type="hidden" id="billStatus" name="billStatus" value="${oi.billStatus}"/>
		<!-- 用于标识提交按钮 -->
		<input type="hidden" id="submitFlag" value="" />
		<div class="pageContent">
			<div class="panel">
				<table class="TableBlock" align="center">
					<tr id="tr1">
					 	<td nowrap>单号:</td>
						<td ><input class="inp_width_98p" id="getProCode" name="getProCode" readonly="readonly" value="${oi.getProCode}" /></td>
						<td nowrap="nowrap" width="20%">建单时间:</td>
						<td width="30%"><input class="inp_width_98p" type="text" id="dctime" name="dctime"
							value="<fmt:formatDate value="${empty oi.dctime?nowDate:oi.dctime}" type="both" dateStyle="long" pattern="yyyy-MM-dd" />" readonly="readonly"/></td>
					</tr>
					<tr>
						<td nowrap>出库仓库:</td>
						<td><select id="whCode" class="inp_width_98p required" name="whCode" onchange="getA()">
							<option></option>
								<c:forEach items='${wh}' var='state'>
   		                 	<option value='${state.code}'>${state.name}</option>
   		                 	</c:forEach>
							</select>
							<script type="text/javascript">
   		                		 $("#whCode").val('${oi.whCode}');
   		                 	</script>
   		             		<input type="hidden" id="whName" name="whName" value="${oi.whName }"/>
						</td>
					 	<td nowrap>出库时间:</td>
						<td><input id="consumingtime" name="consumingtime" class="inp_width_98p required" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" value="<fmt:formatDate value="${oi.consumingtime}" pattern="yyyy-MM-dd" type="both" />" />
							<script>
								var date = new Date();
								$("#consumingtime").val(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate());
							</script>
						</td>
					</tr>
					<tr>
					 	<td nowrap>ERP领料申请单号:</td>
					 	<c:choose>
						<c:when test="${empty oi.oriCode}">
							<td ><select id="oriCode" class="inp_width_98p required" name="oriCode" onchange="getB()">
								<option></option>
								<c:forEach items='${apply}' var='state'>
	   		                 	<option value='${state.getProCode}'>${state.getProCode}</option>
	   		                 	</c:forEach>
								</select>
								<script type="text/javascript">
	   		                		 $("#oriCode").val('${oi.oriCode}');
	   		                 	</script></td>
   		                 </c:when>
	   		            <c:otherwise>	
   		                 	<td > <input id="oriCode" readonly="readonly" class="inp_width_98p required" name="oriCode" value="${oi.oriCode}" /></td>
						</c:otherwise>
   		             	</c:choose>
   		             	<c:if test="${lingliao==1}">
   		             	<td nowrap>MES领料申请单号:</td>
   		             	<td nowrap><input id="deptcode" readonly="readonly" class="inp_width_98p" name="deptcode" value="${oi.deptcode}" /></td></td>
						</c:if>
					</tr>
					<tr>
						<td nowrap>制单人:</td>
						<td>
						    <input type="text" id="createRName" name="createRName" class="inp_width_98p" value="${user.name}" readonly="readonly"/>
							<c:if test="${oi.createRName != null}">
								<script>
									$("#createRName").val("${oi.createRName}");
								</script>
							</c:if>
					  </td>
					  <td nowrap>领用人:</td>
						<td>
						    <input type="text" id="aegnt" name="aegnt" class="inp_width_98p required" value="${oi.aegnt}" />
							<c:if test="${oi.aegnt != null}">
								<script>
									$("#aegnt").val("${oi.aegnt}");
								</script>
							</c:if>
					  </td>
					</tr>
					<tr>
						<td nowrap>备注:</td>
						<td colspan="3"><input id="remark" name="remark"
							style="width: 99%" value="${oi.remark}" /></td>
					</tr>
					<tr>
						<td colspan="4" style="margin-bottom: 10px;"><div
								id="dataGrid1"></div></td>
					</tr>
				</table>
			</div>
			<div class="formBar">
				<ul>
					 <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save" onclick="submitForm(0)">保存</button></div></div></li>
					 <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save1" onclick="submitForm(1)">提交</button></div></div></li>
		        <webres:displaycontroller elementId="LOGIC_PROGET_CK_SP" description="领料出库单审批">
			       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save2" onclick="submitpass(2)">审核通过</button></div></div></li>
			    </webres:displaycontroller>
			    <webres:displaycontroller elementId="LOGIC_PROGET_CK_PH" description="领料出库单驳回">   
			       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save3" onclick="check()">驳回</button></div></div></li>
		       	</webres:displaycontroller>
		       <li><div class="button"><div class="buttonContent"><button type="button" class="print" onclick="CloseDialog()">关闭</button></div></div></li>
				</ul>
			</div>
		</div>
		<script type="text/javascript">
		var ItemStateList = ItemStateData.Rows;
		var addressGrid;
    var column1 = [
    				{ display: '操作',width: 30,
				    render: function (record, rowindex, value, column) {
				  	  var rc = JSON.stringify(record);
				  	  if(record.openBatch=='Y'){
				  		 return "<a href='javascript:ItemWindow("+rc+","+rowindex+")'><img src='${ctx}/js/ligerUI/skins/icons/add.gif' alt='添加' /></a>";
				  	  }else{
				  		 return "<h1>+</h1>";
				  	  }
					  }},
                   { display: 'id', name: 'id',type: 'string',hide:1},
                   { display: 'materialsid', name: 'materialsid',hide:1,width:1},
                   { display: '<font color="gray">物料编码</font>', name: 'code', width: 120,
						  render: function (record, rowindex, value, column) {
							  var rc = JSON.stringify(record);
							  if(record.openBatch=='Y'){
								  return "<a href='javascript:ItemWindow("+rc+","+rowindex+")'>"+record.code+"</a>";
							  	  }else{
							  		 return record.code;
							  	  }
						  	  
						  }},
				    { display: '<font color="gray">名称</font>', name: 'name',width: 120},
				    { display: '<font color="gray">型号</font>', name: 'spec' ,width: 270},
				    { display: '<font color="gray">物料是否可用批次</font>', name: 'openBatch' ,hide:true,width: 150, render: function (item, rowindex, value, column)
					    {
	            	   	if(item.openBatch=="Y"){
	            	   		return "可用";
	            	   	}else{
	            	   		return "不可用";
	            	   	}
				   		
			    }},
				    { display: '<font color="gray">基本单位</font>', name: 'junit' ,width: 100},
				    { display: '<font color="gray">基本单位数量(订单)</font>', name: 'jquantuty',width: 150},
				    { display: '<font color="gray">基本单位已出库数量</font>', name: 'ycksl',width: 150 },
				    { display: '<font color="gray">基本单位库存数量</font>', name: 'kcsl',width: 150 },
				    { display: '<font color="gray">基本单位数量(本次出库)</font>', name: 'actureQuantity',width: 150},
				//    	{ display: '批次<font color="red">*</font>', name: 'batch', width: 120, isSort: false,
				//    		editor: { type: 'selectbatch',whcode:'whCode', databatch:'batchItem',path:'${ctx}/yd/logic/otherOutwh/getWhBatch.do', valueColumnName: 'batch', displayColumnName: 'batch',
				//             ext :
				//                 function (rowdata)
				//                 {
				//                     return {
				//                         onBeforeOpen: function(){
				//                         	getDG().dialog({
				// 					    		title:'选择批次',
				// 					    		width : 300,
				// 								height : 350,
				// 								content: 'url:' + sys_context+'/public/windowalert/itembatch.do?whCode=' + $("#whCode").val()+'&maCode='+rowdata.code,//
				// 					    		lock : true,
				// 					    		max : true,
				// 					    		min : true,
				// 					    		ok: function(){
				// 					    			var rows = this.content.getSelected();
				// 									if (rows != null) {
				// 										addressGrid.updateCell('batch', rows[0].batch, rowdata);
				// 										addressGrid.endEdit();
				// 										getBatchkcQuantity(rowdata);
				// 									}
				// 					    			this.content.Close();
				// 					        		return false;
				// 					    	    },
				// 					    	    cancelVal: '关闭',
				// 					    	    cancel: function(){
				// 					    	    	addressGrid.endEdit();
				// 					    	    } 
				// 					    	}).zindex();
				//                         }, render: function ()
				//                         { 
				//                         	var batchItem = $.parseJSON($("#batchItem").val());
				//             		  		if(batchItem!=null){
				//             			 	for (var i = 0; i < batchItem.length; i++)
				//                      			{
				//                          			if (batchItem[i]['batch'] == rowdata.batch){
				//                             	 		return batchItem[i]['batch'];
				//                          			} 
				//                      			}
				//             		  		}
				//                         }
				
				//                     };
				//                 }
				// 			 }, render: function (item)
				//             {
				//    		 		var batchItem = $.parseJSON($("#batchItem").val());
				// 		  		if(batchItem!=null){
				// 			 	for (var i = 0; i < batchItem.length; i++)
				//          			{
				//              			if (batchItem[i]['batch'] == item.batch){
				//                 	 		return batchItem[i]['batch'];
				//              			} 
				//          			}
				// 		  		}
				//                 return item.batch;
				//             }
				//     },
				       { display: '状态<font color="red">*</font>', name: 'status', width: 100,editor: { type: 'select', data: ItemStateList, valueColumnName: 'ItemStateID', displayColumnName: 'ItemStateName',onChanged:getkcQuantity,
				    	   ext :
              					function (rowdata)
  				                {
           	   				return {
				                        onBeforeOpen: function(){
											if("Y"==rowdata.openBatch){
												$.dialog.alert("该物料可分批次不能选择等级");
												return false;
											}
				                    	}
           	   				};
  				                }}, render: function (item)
				         {
				         for (var i = 0; i < ItemStateList.length; i++)
				         {
				             if (ItemStateList[i]['ItemStateID'] == item.status){
				           	  return ItemStateList[i]['ItemStateName'];
				             }
				         }
				        return item.status;
				     }},
				    { display: '单位<font color="red">*</font>', name: 'unit', width: 100,editor : {
					 	   type:'selecturl',dataItem:'dataItem',path:'${ctx}/yd/basic/measurementUnit/unitlist.do',valueColumnName: 'unitname', displayColumnName: 'unitname',onChanged:function(record,value,column,rowindex,datagrid){
					 		  addressGrid.updateCell('itemBatch', '', record);
					 		  addressGrid.updateCell('val','',record);
					 		  addressGrid.updateCell('quantuty','',record);
					 		  addressGrid.updateCell('actureQuantity','',record);
		                	  }}, render: function (item)
				        {
					 		  var dataitem = $.parseJSON($("#dataItem").val());
					 		  if(dataitem!=null){
					 			 for (var i = 0; i < dataitem.length; i++)
				              {
				                  if (dataitem[i]['unitname'] == item.unit&&dataitem[i]['materialscode']==item.code){
				                 	 addressGrid.updateCell('unitconvert', dataitem[i]['unitconvert'], item);
				                      return dataitem[i]['unitname'];
				                  } 
				              }
					 		  }
				            return item.unit;
				        }},
				        { display: '<font color="gray">单位换算率</font>', name: 'unitconvert',width:80,hide:true},
					{ display: '本次出库数量<font color="red">*</font>', name: 'quantuty',width: 150,editor : {type :'float'}, render: function (item)
							{
						if(item.openBatch=="Y"){
	            	   		item.quantuty=item.val;
	            	   	}else{
						   if(item.quantuty!=''&&item.quantuty!=null&&item.unitconvert!=null&&item.unitconvert!=''){
							   addressGrid.updateCell('actureQuantity', item.quantuty*item.unitconvert, item);
						   }
	            	   	}
						   return item.quantuty;
						}},
					{ display: '<font color="gray">值</font>', name: 'val' ,width:1,hide:1},
				    { display: '<font color="gray">批次详细信息</font>', name: 'itemBatch',width : 1,hide:1}
//     { display: '分多批操作',width: 150,
// 	        render: function (record, rowindex, value, column) {
// 		  	   return "<a href='javascript:manyBatch(" + rowindex + ")'>分多批次</a>";
// 		  }}
     ];
    var column2 = [
				  { display: '操作',width: 30,
				    render: function (record, rowindex, value, column) {
				  	  var rc = JSON.stringify(record);
				  	  if(record.openBatch=='Y'){
				  		 return "<a href='javascript:ItemWindow("+rc+","+rowindex+")'><img src='${ctx}/js/ligerUI/skins/icons/add.gif' alt='添加' /></a>";
				  	  }else{
				  		 return "<h1>+</h1>";
				  	  }
					  }},
                   { display: 'id', name: 'id',type: 'string',hide:1},
                   { display: 'materialsid', name: 'materialsid',hide:1,width:1},
                   { display: '<font color="gray">物料编码</font>', name: 'code', width: 120,
						  render: function (record, rowindex, value, column) {
							  var rc = JSON.stringify(record);
							  if(record.openBatch=='Y'){
								  return "<a href='javascript:ItemWindow("+rc+","+rowindex+")'>"+record.code+"</a>";
							  	  }else{
							  		 return record.code;
							  	  }
						  	  
						  }},
                   { display: '<font color="gray">名称</font>', name: 'name',width: 120},
                   { display: '<font color="gray">型号</font>', name: 'spec' ,width: 270},
                   { display: '<font color="gray">物料是否可用批次</font>', name: 'openBatch' ,width: 150,hide:true, render: function (item, rowindex, value, column)
					    {
	            	   	if(item.openBatch=="Y"){
	            	   		return "可用";
	            	   	}else{
	            	   		return "不可用";
	            	   	}
				   		
			    }},
                   { display: '<font color="gray">基本单位</font>', name: 'junit' ,width: 100},
                   { display: '<font color="gray">基本单位数量(订单)</font>', name: 'jquantuty',width: 150},
                   { display: '<font color="gray">基本单位已出库数量</font>', name: 'ycksl',width: 150 },
                   { display: '<font color="gray">基本单位数量(本次出库)</font>', name: 'actureQuantity',width: 150},
                   { display: '<font color="gray">基本单位库存数量</font>', name: 'kcsl',width: 150 },
//                    { display: '批次<font color="red">*</font>', name: 'batch',width: 120},
                     { display: '状态<font color="red">*</font>', name: 'status', width: 100, render: function (item)
                        {
                        		for (var i = 0; i < ItemStateList.length; i++)
                        			{
                            			if (ItemStateList[i]['ItemStateID'] == item.status){
                          	  		return ItemStateList[i]['ItemStateName'];
                            			}
                        			}
                        		return item.status;
                    		}
  				   }, 
                   { display: '单位<font color="red">*</font>', name: 'unit' ,width: 100},
                   { display: '<font color="gray">单位换算率</font>', name: 'unitconvert',width:80,hide:true},
                   { display: '本次出库数量<font color="red">*</font>', name: 'quantuty',width: 150},
                   { display: '<font color="gray">值</font>', name: 'val' ,width:1,hide:1},
                   { display: '<font color="gray">批次详细信息</font>', name: 'itemBatch',width : 1,hide:1}];
                
    
    var column3 = null;
    if ('${xx}' == 1 || '${xx}'==4){
    	column3 = column1;
    }else 
    	column3 = column2;
    
    addressGrid = $("#dataGrid1").ligerGrid({
		 columns: column3,
	                    enabledEdit : true,
	                    usePager: true,
	      				width : '99%',
	      				pageSize:1000,
	      				pageSizeOptions:[1000],
	      				parms:[{ name : 'id' , value : '${oi.id}'}],
      		        	url : basic_Url+"/griditems.do",
	      				rownumbers : false,
	      				checkbox : true,
	                    height : '90%',
		toolbar : {
			items : [{
				text : '删除',
				click : function() {
					if ('${xx}' == 1 || '${xx}'==4){
					addressGrid.deleteSelectedRow();
					}
				},
				img : '${ctx}/js/ligerUI/skins/icons/delete.gif'
			}]
		}});
	
	
	/* <c:forEach items="${axxJson}" var="row">
	addressGrid.addRow2({
			id : "${row.id}",
	   		materialsid:"${row.materialsid}",
	   		code : "${row.code}",
	   		name : "${row.name}",
	   		spec : "${row.spec}",
	   		junit : "${row.junit}",
	   		unit : "${row.unit}",
	   		unitconvert : "${row.unitconvert}",
	   		status : "${row.status}",
	   		quantuty : "${row.quantuty}",
// 	   		batch:"${row.batch}",
	   		jquantuty : "${row.jquantuty}",
	   		actureQuantity : "${row.actureQuantity}",
			kcsl : '${row.kcsl}',
			ycksl : '${row.ycksl}',
			itemBatch:'${row.itemBatch}',
			openBatch : "${row.openBatch}",
      	   	val : "${row.val}"
	});
    </c:forEach> */
    
 
    function getkcQuantity(e){
    	var rowData=addressGrid.getRow($(e).parent()[0]);
    	if (rowData.openBatch!="Y"){
    		 $.ajax({
      		      url: "${ctx}/yd/logic/proget/getStorageQuaitity.do",
      		      global: false,
      		      type: "POST",
      		      dataType: "json",
      		      data: ({
      		    	maCode : rowData.code,
      				whCode : $("#whCode").val(),
      				hubCode : rowData.hubCode,
      				status : rowData.status,
      				batch : "NoBatch"
      		      }),		     
      		      success: function(msg){
      		    	rowData.kcsl = msg;
      			 	rowData.auto = true;
      	   			addressGrid.updateCell('kcsl',msg,rowData);
      		      }
      	   });
   		}else{
   			return false;
   		}
    }
    
//     function getBatchkcQuantity(rowData){
//     	if (rowData.batch){
//     		 $.ajax({
//       		      url: "${ctx}/yd/logic/otherOutwh/getStorageQuaitity.do",
//       		      global: false,
//       		      type: "POST",
//       		      dataType: "json",
//       		      data: ({
//       		    	maCode : rowData.code,
//       				whCode : $("#whCode").val(),
//       				hubCode : rowData.hubCode,
//       				status : rowData.status,
//       				batch : rowData.batch
//       		      }),		     
//       		      success: function(msg){
//       		    	rowData.kcsl = msg;
//       			 	rowData.auto = true;
//       	   			addressGrid.updateCell('kcsl',msg,rowData);
//       		      }
//       	   });
//    		}else{
//    			$.dialog.alert("请先选择批次");
//    		}
//     }
//     function manyBatch(index){
//     	//var rowData = grid.data.Rows;
//     	var data= addressGrid.getData();
//     	var manager = $("#dataGrid1").ligerGetGridManager();
//     	manager.addRow2(data[index]);
//     }
function ItemWindow(rc,index) {
 	if(undefined==$("#whCode").val() || ""==$("#whCode").val()){
			$.dialog.alert("请先选择仓库");
			return ;
	}
 	var manager = $("#dataGrid1").ligerGetGridManager();
		getDG().dialog(
				{
					title : '批次管理',
					width : 700,
				//	height : 450,
					height : 350,
					content : 'url:' + sys_context+ '/yd/logic/proget/itemManager.do?data='+encodeURIComponent(JSON.stringify(manager.getRow(rc.__index)))+'&billStatus=${oi.billStatus}'+'&whcode='+$("#whCode").val(),//
					lock : true,
					max : true,
					min : true,
					ok : function() {
// 						this.content.yz();
// 						if(this.content.ba){
// 						var dt = this.content.grid.getData();
// 						if (dt != null) {
// 							rc.actureQuantity=this.content.jnum;
// 							rc.quantuty=this.content.num;
// 							rc.itemBatch=JSON.stringify(dt);
// 							rc.kcsl=this.content.storageQuantity;
// 							addressGrid.updateCell('actureQuantity', rc.actureQuantity, manager.getRow(rc.__index));
// 							addressGrid.updateCell('quantuty', rc.quantuty, manager.getRow(rc.__index));
// 							addressGrid.updateCell('itemBatch',rc.itemBatch, manager.getRow(rc.__index));
// 							addressGrid.updateCell('val',rc.quantuty, manager.getRow(rc.__index));
// 							addressGrid.updateCell('kcsl',rc.kcsl, manager.getRow(rc.__index));
// 							addressGrid.updateRow(manager.getRow(rc.__index));
// 							this.content.Close();
// 							}else{
// 								this.content.Close();
// 							}
							
// 						}
// // 						return false;
// 						var getSelectedHub = this.content.getSelected();
// // 						alert("getSelectedHub:"+getSelectedHub.toSource());
					
						
// 							this.content.Close();
// 						}
// 						return false;
						
						
						this.content.yz();
						if(this.content.ba){
						var getSelectedHub = this.content.getSelected();
						if (getSelectedHub != null) {
							rc.kcsl=this.content.storageQuantity;
							rc.actureQuantity=this.content.jnum;
							rc.quantuty=this.content.num;
							rc.val=this.content.num;
							rc.itemBatch=JSON.stringify(getSelectedHub);
							addressGrid.updateCell('kcsl',rc.kcsl, manager.getRow(rc.__index));
					   		addressGrid.updateCell('actureQuantity',rc.actureQuantity, manager.getRow(rc.__index));
					   		addressGrid.updateCell('quantuty',rc.quantuty, manager.getRow(rc.__index));
					   		addressGrid.updateCell('val',rc.val, manager.getRow(rc.__index));
							addressGrid.updateCell('itemBatch',rc.itemBatch, manager.getRow(rc.__index));
							addressGrid.updateRow(manager.getRow(rc.__index));
							this.content.Close();
							}else{
								this.content.Close();
							}
							
						}
						return false;
					},
					cancelVal : '关闭',
					cancel : true
				}).zindex();
	}
    </script>
	</form>
</body>
</html>
